/*
IN1  - PA8-UH     -D7
IN2  - PA9-VH     -D8
IN3  - PA10-WH    -D2

EN1  - PC10
EN2  - PC11
EN3  - PC12

BKIN - PA6      -D5
*/

#include <Arduino.h>
// Open loop motor control example
#include <SimpleFOC.h>

// BLDC driver instance
BLDCDriver3PWM driver = BLDCDriver3PWM(7, 8, 2, 9); //9 5 6

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);

  /* en */
  pinMode(PC10, OUTPUT);
  digitalWrite(PC10, HIGH); 

  pinMode(PC11, OUTPUT);
  digitalWrite(PC11, HIGH); 

  pinMode(PC12, OUTPUT);
  digitalWrite(PC12, HIGH); 

  pinMode(PA6, OUTPUT);
  digitalWrite(PA6, HIGH); 

  Serial.begin(115200);
  Serial.println("start……");


  // pwm frequency to be used [Hz]
  // for atmega328 fixed to 32kHz
  // esp32/stm32/teensy configurable
  driver.pwm_frequency = 50000;
  // power supply voltage [V]
  driver.voltage_power_supply = 10;
  // Max DC voltage allowed - default voltage_power_supply
  driver.voltage_limit = 10;

  // driver init
  driver.init();

  // enable driver
  driver.enable();

  _delay(1000);
  
  Serial.println("pwm inited");
}

void loop() {
  // put your main code here, to run repeatedly:
 
    // setting pwm
    // phase A: 3V
    // phase B: 6V
    // phase C: 9V
  driver.setPwm(3,6,9);

  digitalWrite(13, HIGH); 
  delay(50);
  digitalWrite(13, LOW);  
  delay(50);
  Serial.println("set");

}